home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE18 / EX3.C < prev    next >
C/C++ Source or Header  |  1994-12-27  |  3KB  |  81 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc (HWND  hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.  
  6.    switch (uMsg)   /* process windows messages */
  7.    {
  8.        case WM_PAINT:
  9.             {
  10.                HWND         hCBOwner;        /* handle to owner of clipboard */
  11.                HWND         hCBViewer;       /* handle of first viewer of clipboard */
  12.                HWND         hCBOpenWnd;      /* handle of window with clipboard open */
  13.                char         cBuf [128];      /* TextOut buffer work area */
  14.                char         cName [64];      /* name of window work area */
  15.                PAINTSTRUCT  ps;
  16.                BeginPaint( hWnd, &ps );   /*  Erase the background, Fill in the ps structure */
  17.                OpenClipboard(hWnd);
  18.                EmptyClipboard();
  19.                SetClipboardData(CF_TEXT, 0);
  20.                CloseClipboard();       
  21.                hCBOwner = GetClipboardOwner( );   /* return the owner of the clipboard */
  22.                if (hCBOwner == NULL)
  23.                   lstrcpy( cName, "<None>" ) ;
  24.                else
  25.                   GetWindowText( hCBOwner, cName, 63 );
  26.                /* show who is the owner of the clipboard */
  27.  
  28.  
  29.  
  30.                TextOut( ps.hdc, 10, 10, cBuf, 
  31.                         wsprintf( cBuf, "Clipboard Owner:  %s", (LPSTR) cName ) );
  32.                hCBViewer = GetClipboardViewer( ); /* return the first viewer of the clipboard */
  33.                if (hCBViewer == NULL)
  34.                    lstrcpy( cName, "<None>" ) ;
  35.                else
  36.                    GetWindowText( hCBViewer, cName, 63 );
  37.                TextOut ( ps.hdc, 10, 30, cBuf, wsprintf ( cBuf,
  38.                        "Clipboard Viewer:  %s", (LPSTR) cName ) ) ;
  39.                /* return the window that last opened the clipboard  */
  40.                hCBOpenWnd = GetOpenClipboardWindow( );
  41.                if (hCBOpenWnd == NULL)
  42.                   lstrcpy( cName, "<None>" );
  43.                else
  44.                   GetWindowText( hCBOpenWnd, cName, 63 );
  45.                TextOut( ps.hdc, 10, 50, cBuf, wsprintf (cBuf,
  46.                        "Opened Clipboard:  %s", (LPSTR) cName) );
  47.                EndPaint( hWnd, &ps ) ;  /* validate the rectangle - stop painting */
  48.             }
  49.             break ;
  50.  
  51.        case WM_CHANGECBCHAIN:      /* change in clipboard viewer chain */
  52.                InvalidateRect(hWnd, NULL, TRUE);   // force paint and refresh
  53.                break;
  54.  
  55.        case WM_COMMAND:   
  56.                switch (wParam)
  57.                { 
  58.                    case IDM_TEST:      
  59.                       
  60.                       InvalidateRect( hWnd, NULL, TRUE ); /* provoke a paint to print report */
  61.                    break;
  62.                    case IDM_EXIT:
  63.                       DestroyWindow(hWnd);
  64.                    break;
  65. #include <aboutopt.c>
  66.                }
  67.                break;
  68.  
  69. #include <rbutton.c>
  70.  
  71.       case WM_DESTROY:
  72.               PostQuitMessage(0);
  73.       break;
  74.       default:
  75.               return DefWindowProc(hWnd, uMsg, wParam, lParam);
  76.    }
  77.    return (0L);
  78. }
  79.  
  80. #include <about.c>
  81.